//
//  BasicViewController.m
//  ShaoPingWuLiu
//
//  Created by WeiPan on 15/11/5.
//  Copyright (c) 2015年 WPJoe. All rights reserved.
//

#import "WPBasicViewController.h"

@interface WPBasicViewController ()


@end

@implementation WPBasicViewController

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
        //orientation
    
    self.navigationController.navigationBar.hidden = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = COLOR_RGB(235, 11, 11, 1);
    self.view.backgroundColor                            = BGCOLOR;
    self.automaticallyAdjustsScrollViewInsets            = NO;
}

#pragma mark - init
- (void)initializeAlertControllerWithMessage:(NSString *)msg {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alertController animated:YES completion:nil];
}
- (void)initializeAlertControllerWithMessageAndDismiss:(NSString *)msg {
    if (self.presentedViewController) {
        [self.presentedViewController dismissViewControllerAnimated:NO completion:nil];
    }
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alertController animated:YES completion:nil];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [alertController dismissViewControllerAnimated:YES completion:nil];
    });
}

- (void)initializeAlertControllerWithMessage:(NSString *)msg withHandelBlock:(void(^)(id action)) action {
    if (self.presentedViewController) {
        [self.presentedViewController dismissViewControllerAnimated:NO completion:nil];
    }
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:action]];
    [self presentViewController:alertController animated:YES completion:nil];
}
- (void)pushToNextController:(UIViewController *)nextVC withVCTitle:(NSString *)title {
    UIBarButtonItem *goback_item = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = goback_item;
    nextVC.hidesBottomBarWhenPushed = YES;
    nextVC.title = title;
    [self.view endEditing:YES];
    [self.navigationController pushViewController:nextVC animated:YES];
}
- (void)presentToLoginViewController {
    UINavigationController * loginNavVC = [[UINavigationController alloc]initWithRootViewController:[[NSClassFromString(@"WPPwdLoginViewController") alloc]init]];
    __weak typeof(self)weakself = self;
    [self.tabBarController presentViewController:loginNavVC animated:YES completion:^{
        weakself.tabBarController.selectedIndex = 0;
    }];
}
#pragma mark - responds events
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
#pragma mark - getter
- (UIView *)BasicStatusBackView {
    if (!_BasicStatusBackView) {
        _BasicStatusBackView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, -staBar_height, SCREEN_SIZE.width, staBar_height)];
            view.backgroundColor = COLOR_RGB(13, 13, 12, 1);
            view;
        });
    }
    return _BasicStatusBackView;
}
@end
